//销售员第二层

const { salesmansLogin, getSellersOrderById } = require('../dao/salesmansDao')

//登录
//加密 身份认证
// const bcrypt = require('bcrypt')
const jwt = require('jsonwebtoken')
module.exports.salesmansLogin = async a => {
    const data = await salesmansLogin(a)
    if (data.length > 0) {
        const { account, password } = a
        //  const result =bcrypt.compareSync(password,data[0].password)
        // if(result){
            const token = jwt.sign(
                {account},
                'admins',   //密钥
                {expiresIn: 60*10} //token有效期
            )
            return{
                message:'销售员登录成功',
                status:1,
                token,
                data
            }
        // }else{
        //     return{
        //         message:'销售员登录失败,密码错误',
        //         status:0
        //     }
        // }  
    } else {
        return {
            message: '登录失败,没有该销售员',
            status: 0
        }
    }
}
module.exports.getSellersOrderById = async function (params) {
    console.log(params)
    const data = await getSellersOrderById(params)
    try {
        return {
            message: "获取成功",
            status: 1,
            data
        }
    } catch (error) {
        return {
            message: "获取失败",
            status: 0,
        }
    }
}
